package de.geckocraft.AchievementCraft.mysql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import de.geckocraft.AchievementCraft.mysql.*;

import org.bukkit.plugin.Plugin;

public class broker
{
	static Connection con = null;
	static Statement stmt = null;
	static ResultSet rs = null;
	
	public static void connect()
	{
		
		String address = "jdbc:mysql://" + mysqlconfig.getconfig().getString("ip") + ":" + mysqlconfig.getconfig().getString("port") + "/" + mysqlconfig.getconfig().getString("database"); 
		System.out.println(address);
		try
		{
			con = DriverManager.getConnection(address, mysqlconfig.getconfig().getString("user"), mysqlconfig.getconfig().getString("password"));
			stmt = con.createStatement();
			rs = stmt.executeQuery("SELECT * FROM test");
			
			while(rs.next())
			{
				System.out.println(rs.getString("name"));
			}
		}
		catch(SQLException e)
		{
			Plugin p = de.geckocraft.AchievementCraft.main.main.getPlugin();
			p.getPluginLoader().disablePlugin(p);
			System.out.println("[" + p.getName() + "]Can't connect to Database");
			System.out.println(e);
		}
	}
	
}
